package com.yi.wood.web.config;


import com.yi.wood.web.interceptor.AuthTokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;
/**
 * @author MoYi
 * Ctrl配置
 */
@Configuration
public class WoodWebCtrlConfig implements WebMvcConfigurer {
    /**
     * 排拦截器排序的URL
     */
    private List<String> exList = new ArrayList<>();

    {
        exList.add("/api/user/login");
        exList.add("/api/user/register");
        exList.add("/api/user/ver");
    }

    private final AuthTokenInterceptor authTokenInterceptor;

    @Autowired
    public WoodWebCtrlConfig(AuthTokenInterceptor authTokenInterceptor) {
        this.authTokenInterceptor = authTokenInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加一个拦截器
        registry.addWebRequestInterceptor(authTokenInterceptor).addPathPatterns("/api/**").excludePathPatterns(exList);
    }
}
